package com.ruoyi.course.service.impl;

import java.util.List;

import com.ruoyi.common.constant.SysConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.course.mapper.SysMaterialMapper;
import com.ruoyi.course.domain.SysMaterial;
import com.ruoyi.course.service.ISysMaterialService;

/**
 * 资料Service业务层处理
 * 
 * @author YJF
 * @date 2023-05-11
 */
@Service
public class SysMaterialServiceImpl implements ISysMaterialService 
{
    @Autowired
    private SysMaterialMapper sysMaterialMapper;

    /**
     * 查询资料
     * 
     * @param materialId 资料主键
     * @return 资料
     */
    @Override
    public SysMaterial selectSysMaterialByMaterialId(Long materialId)
    {
        return sysMaterialMapper.selectSysMaterialByMaterialId(materialId);
    }

    /**
     * 查询资料列表
     * 
     * @param sysMaterial 资料
     * @return 资料
     */
    @Override
    public List<SysMaterial> selectSysMaterialList(SysMaterial sysMaterial)
    {
        if(StringUtils.isNull( sysMaterial.getDelFlag())){
            sysMaterial.setDelFlag(SysConstants.CONSTANT_STR0);
        }
        return sysMaterialMapper.selectSysMaterialList(sysMaterial);
    }

    /**
     * 新增资料
     * 
     * @param sysMaterial 资料
     * @return 结果
     */
    @Override
    public int insertSysMaterial(SysMaterial sysMaterial)
    {
        sysMaterial.setCreateTime(DateUtils.getNowDate());
        sysMaterial.setUpdateTime(DateUtils.getNowDate());
        return sysMaterialMapper.insertSysMaterial(sysMaterial);
    }

    /**
     * 修改资料
     * 
     * @param sysMaterial 资料
     * @return 结果
     */
    @Override
    public int updateSysMaterial(SysMaterial sysMaterial)
    {
        sysMaterial.setUpdateTime(DateUtils.getNowDate());
        return sysMaterialMapper.updateSysMaterial(sysMaterial);
    }

    /**
     * 批量删除资料
     * 
     * @param materialIds 需要删除的资料主键
     * @return 结果
     */
    @Override
    public int deleteSysMaterialByMaterialIds(Long[] materialIds)
    {
        return sysMaterialMapper.deleteSysMaterialByMaterialIds(materialIds);
    }

    /**
     * 删除资料信息
     * 
     * @param materialId 资料主键
     * @return 结果
     */
    @Override
    public int deleteSysMaterialByMaterialId(Long materialId)
    {
        return sysMaterialMapper.deleteSysMaterialByMaterialId(materialId);
    }
}
